package cn.cdeden.knowledge.utils;

import org.springframework.util.ObjectUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * 一些不好归类的常用工具类
 */
public class MyUtil {

    public static String getUUID() {
        return UUID.randomUUID().toString().replace("-", "");
    }




    public static String getUUID(int len) {
        if (0 >= len) {
            return null;
        }

        String uuid = getUUID();
        System.out.println(uuid);
        StringBuffer str = new StringBuffer();

        for (int i = 0; i < len; i++) {
            str.append(uuid.charAt(i));
        }

        return str.toString();
    }



    public static boolean isDeadTime(Date deadTime) {
//        deadTime
        if (ObjectUtils.isEmpty(deadTime)) { //时间为空为过期
            return false;
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        //当前时间
        Date currentTime = new Date();// 当前时间

        if (currentTime.compareTo(deadTime) > 0) {//过期
            return true;
        }
        return false;

    }

}
